import { LSPMessageWithFrame } from "./LSPMessageWithFrame";
import { LSPMessage } from "./LSPMessage";
export class LSPMessageFactory {
  static diagramId = 0;
  static textDocumentId = 0;

  public static getDiagramMessage(
    frameId: number,
    lastFrame: boolean,
    frame: string
  ): LSPMessageWithFrame {
    let message = new LSPMessageWithFrame();
    message.jsonrpc = "2.0";
    message.id = LSPMessageFactory.diagramId++;
    message.frameId = frameId;
    message.lastFrame = lastFrame;
    message.frame = frame;
    return message;
  }

  public static getTextDocumentMessage(
    frameId: number,
    lastFrame: boolean,
    frame: string
  ): LSPMessageWithFrame {
    let message = new LSPMessageWithFrame();
    message.jsonrpc = "2.0";
    message.id = LSPMessageFactory.textDocumentId++;
    message.frameId = frameId;
    message.lastFrame = lastFrame;
    message.frame = frame;
    return message;
  }
  public static getLSPMessage(
    messageId: number,
    frameId: number,
    lastFrame: boolean,
    frame: string
  ): LSPMessageWithFrame {
    let message = new LSPMessageWithFrame();
    message.jsonrpc = "2.0";
    message.id = messageId;
    message.frameId = frameId;
    message.lastFrame = lastFrame;
    message.frame = frame;
    return message;
  }
  //无分帧
  public static getMessageNoFraming(
    messageId: number,
    method: string,
    params: object
  ) {
    let message = new LSPMessage();
    message.jsonrpc = "2.0";
    message.id = messageId;
    message.method = method;
    message.params = params;
    return message;
  }
}
